package com.szzg10.thinking.chapter18;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class OSExecute {

	public static void command(String command) throws IOException {
		ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
		Process process = processBuilder.start();
		
		InputStream inputStream = process.getInputStream();
		InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
		BufferedReader reader = new BufferedReader(inputStreamReader);
		
		String str;
		while((str = reader.readLine()) != null) {
			System.out.println(str);
		}
		reader.close();
		
		InputStream errorStream = process.getErrorStream();
		InputStreamReader inputStreamReaderError = new InputStreamReader(errorStream);
		BufferedReader readerError = new BufferedReader(inputStreamReaderError);
		
		while((str = readerError.readLine()) != null) {
			System.out.println(str);
		}
		readerError.close();
	}
}
